<template>
	<view class="content">
	
		<scroll-view class="scroll" scroll-y>
			<view class="scroll-content">
				<view class="introduce-section">
					<text class="title">{{detailData.title}}</text>
					<view class="introduce">
						<text>{{applicationConfig.appicationName}}</text>
						<text>{{detailData.numberOfReading}}阅读</text>
						<text>{{detailData.publishTime}}</text>
					</view>
					
					<rich-text :nodes="detailData.htmlNodes"></rich-text>
					
				</view>
				
				<view class="container" v-show="loading === false">
					<!-- 推荐 -->
					<view class="s-header">
						<text class="tit">相关推荐</text>
					</view>
					<view class="rec-section" v-for="item in newsList" :key="item.articleUuid">
						<view class="rec-item" @click="navToDetails(item)">
							<view class="left">
								<text class="title">{{item.title}}</text>
								<view class="bot">
									<text class="author">{{applicationConfig.applicationName}}</text>
									<text class="time">{{item.publishTime}}</text>
								</view>
							</view>
							<view class="right">
								<image class="img" :src="item.coverImageUrl" mode="aspectFill"></image>
							</view>
						</view>
					</view>
				</view>
				<!-- 加载图标 -->
				<customLoading class="custom-loading" v-if="loading"></customLoading>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import json from '@/Json';
	import customLoading from '@/components/custom-loading/custom-loading';
	import htmlParser from '@/config/html-parser'
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			customLoading
		},
		data() {
			return {
				loading: true,
				detailData: {},
				newsList: [],
				evaList: [],
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo', 'footPrint', 'applicationConfig'])
		},
		onLoad(options){
			var id = options.id;
			this.loadNewsDetail(id);
			this.loadNewsList();
		},
		methods: {
			loadNewsList(tagName){
				let that = this;
				this.$api.request.articleList({
					tagDTO:{
						tagName: tagName
					},
					startIndex:0,
					pageSize:5
				}, function(res) {
					if (res.body.status.statusCode === '0') {
						that.newsList = res.body.data.articles;
						that.loading = false;
					}
				})
			},
			//获取文章详情
			loadNewsDetail(id){
				let that = this;
				this.$api.request.articleInfo({
					articleUuid:id
				}, function(res) {
					if (res.body.status.statusCode === '0') {
						that.detailData = res.body.data;
						that.loadNewsList(that.detailData.tagDTO.tagName);
						var content = that.detailData.content;
						content = content.replace(/<!DOCTYPE html>/g,"").replace(/<html>/g,"").replace(/<\/html>/g,"").replace(/<head>/g,"").replace(/<\/head>/g,"").replace(/<body>/g,"").replace(/<\/body>/g,"")
						// var htmlString = content.replace(/\\/g, "").replace(/<img/g, "<img style=\"display:none;\"");
						that.detailData.htmlNodes = htmlParser(content);
					}
				})
			},
			//新闻详情
			navToDetails(item){
				let url = '';
				if(item.articleType==='1' && item.linkType=='自定义内容')	
					url = '/pages/content/details?id='+item.articleUuid;
				if(item.articleType==='1' && item.linkType=='外部链接')
					url = '/pages/content/webView?src='+item.content;
				if(item.articleType==='2' || item.articleType==='3')
					url = '/pages/content/videoDetails?id='+item.articleUuid;
				uni.navigateTo({
					url:url
				})
			},
			
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.content{
		display: flex;
		flex-direction: column;
		height: 100%;
		background: #fff;
	}
	.video-wrapper{
		height: 422upx;
		
		.video{
			width: 100%;
			height: 100%;
		}
	}
	.scroll{
		flex: 1;
		position: relative;
		background-color: $page-color-base;
		height: 0;
	}
	.scroll-content{
		display: flex;
		flex-direction: column;
	}
	/* 简介 */
	.introduce-section{
		display: flex;
		flex-direction: column;
		padding: 20upx 30upx;
		background: #fff;
		line-height: 1.5;
		
		.title{
			font-size: 36upx;
			color: #303133;
			margin-bottom: 16upx;
		}
		.introduce{
			display: flex;
			font-size: 26upx;
			color: $font-color-light;
			text{
				margin-right: 16upx;
			}
		}
	}
	/* 点赞等操作 */
	.actions{
		display: flex;
		justify-content: space-around;
		align-items: center;
		line-height: 1.3;
		padding: 10upx 40upx 20upx;
	
		.action-item{
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			font-size: 24upx;
			color: $font-color-light;
		}
	}

	.s-header{
		padding: 20upx 30upx;
		font-size: 30upx;
		color: $font-color-dark;
		background: #fff;
		margin-top: 16upx;
		
		&:before{
			content: '';
			width: 0;
			height: 40upx;
			margin-right: 24upx;
			border-left: 6upx solid $base-color;
		}
	}
	/* 推荐列表 */
	.rec-section{
		background-color: #fff;
		.rec-item{
			display: flex;
			padding: 20upx 30upx;
			position: relative;
			&:after{
				content: '';
				position: absolute;
				left: 30upx;
				right: 0;
				bottom: 0;
				height: 0;
				border-bottom: 1px solid #eee;
				transform: scaleY(50%);
			}
		}
		.left{
			flex: 1;
			padding-right: 10upx;
			overflow: hidden;
			position: relative;
			padding-bottom: 52upx;
			.title{
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
				font-size: 32upx;
				color: $font-color-dark;
				line-height: 44upx;
			}
			.bot{
				position: absolute;
				left: 0;
				bottom: 4upx;
				font-size: 26upx;
				color: $font-color-light;
			}
			.time{
				margin-left: 20upx;
			}
		}
		.right{
			width: 220upx;
			height: 140upx;
			flex-shrink: 0;
			position: relative;
			.img{
				width: 100%;
				height: 100%;
			}
			
		}
	}
</style>
